package c2.cross.business.championrace.handler;

import c2.cross.business.championrace.ChampionRaceModule;
import cate.game.pvp.championrace.timer.ChampionRaceTimerTask;
import lombok.extern.slf4j.Slf4j;

import static cate.game.event.championrace.ChampionRaceTimerEvent.EventType.*;


@Slf4j
public class ChampionRaceControlSettingHandler extends AbstractChampionRaceSettingHandler{
    public ChampionRaceControlSettingHandler(ChampionRaceModule parent) {
        super(parent);
    }

    @Override
    public void run() {

    }

    @Override
    public boolean runSettingFunction(ChampionRaceTimerTask.Setting setting) {
        switch (setting.getEventType()) {
            case OPEN:
                return runOpenWith(setting);
            case CLOSE:
                return runCloseWith(setting);
            case SWITCH:
                return runSwitchWith(setting);
            case RANK_SETTLE:
                return runRankSettleWith(setting);
            case INVITATION:
                return runInvitationWith(setting);
            case SHOW:
                return runShowWith(setting);
            case REST:
                return runRestWith(setting);
            default:
                break;
        }
        return true;
    }

    @Override
    public boolean isMatch(ChampionRaceTimerTask.Setting setting) {
        return setting.getEventType() == OPEN
                || setting.getEventType() == CLOSE
                || setting.getEventType() == SWITCH
                || setting.getEventType() == RANK_SETTLE
                || setting.getEventType() == INVITATION
                || setting.getEventType() == SHOW
                || setting.getEventType() == REST;
    }

    private boolean runOpenWith(ChampionRaceTimerTask.Setting setting) {
        parent.openSeason(setting);
        return true;
    }

    private boolean runCloseWith(ChampionRaceTimerTask.Setting setting) {
        parent.closeSeason(setting);
        return true;
    }

    private boolean runSwitchWith(ChampionRaceTimerTask.Setting setting) {
        parent.switchSeason(setting);
        return true;
    }

    private boolean runRankSettleWith(ChampionRaceTimerTask.Setting setting) {
        if (!parent.canChangeSpec(setting, RANK_SETTLE.getFlag(), false)) {
            return true;
        }

        return parent.rankSettle(setting);
    }

    private boolean runInvitationWith(ChampionRaceTimerTask.Setting setting) {
        parent.changeSpec(setting, INVITATION.getFlag());
        return true;
    }

    private boolean runShowWith(ChampionRaceTimerTask.Setting setting) {
        parent.changeSpec(setting, SHOW.getFlag());
        return true;
    }

    private boolean runRestWith(ChampionRaceTimerTask.Setting setting) {
        parent.changeSpec(setting, REST.getFlag());
        return true;
    }
}
